package ModelLayer;
import java.util.ArrayList;

public class DVD 
{
    private long id;
    private String title;
    private String artist;
    private String publicationDate;
    private ArrayList<Copy> copyList;
    
    public DVD()
    {
        id = 0;
        title = "";
        artist = "";
        publicationDate = "";
        copyList = new ArrayList<Copy>();
    }

    public DVD(long _id, String _title, String _artist, String _publicationDate)
    {
        id = _id;
        title = _title;
        artist = _artist;
        publicationDate = _publicationDate;
        copyList = new ArrayList<Copy>();
    }
    
    public void addCopy(Copy _copy)
    {
        copyList.add(_copy);
    }
    
    public Copy getCopy(long _copySerialNumber)
    {
        Copy c = new Copy();
        c = null;
        for (int i=0; i<copyList.size(); i++)
        {
            if (copyList.get(i).getSerialNumber() == _copySerialNumber)
            {
                c = copyList.get(i);
                return c;
            }
            else
                c = null;
        }
        
        return c;
    }
    
    public void updateCopy(Copy _c)
    {
        getCopy(_c.getSerialNumber()).setPurchaseDate(_c.getPurchaseDate());
        getCopy(_c.getSerialNumber()).setPurchasePrice(_c.getPurchasePrice());
        getCopy(_c.getSerialNumber()).setAvailability(_c.getAvailability());
    }
    
    public void deleteCopy(long _copySerialNumber)
    {
        for (int i=0; i<copyList.size(); i++)
        {
            if(copyList.get(i).getSerialNumber() == _copySerialNumber)
                copyList.remove(i);
        }
    }
    
    public ArrayList<Copy> listAllCopies()
    {
        return copyList;
    }

    public void setId(long _id)
    {
        id = _id;
    }
    
    public long getId()
    {
        return id;
    }
    
    public void setTitle(String _title)
    {
        title = _title;
    }
    
    public String getTitle()
    {
        return title;
    }
    
    public void setArtist(String _artist)
    {
        artist = _artist;
    }
    
    public String getArtist()
    {
        return artist;
    }
    
    public void setPublicationDate(String _publicationDate)
    {
        publicationDate = _publicationDate;
    }
    
    public String getPublicationDate()
    {
        return publicationDate;
    }
}
